@file:Suppress("unused")

package com.example.demo.model.mall

import xyz.erupt.annotation.*
import xyz.erupt.annotation.sub_field.*
import xyz.erupt.annotation.sub_field.sub_edit.*
import xyz.erupt.jpa.model.*
import java.util.*
import javax.persistence.*

@Erupt(name = "优惠券管理")
@Table(name = "mall_goods_coupon")
@Entity
class Coupon : BaseModel() {

    @EruptField(
        views = [View(title = "名称")],
        edit = Edit(
            title = "名称",
            notNull = true,
            search = Search(),
            inputType = InputType(fullSpan = true),
        ),
    )
    var name: String = ""

    @EruptField(
        views = [View(title = "金额")],
        edit = Edit(
            title = "金额",
            notNull = true,
            search = Search(),
        ),
    )
    var price: Double = 0.0

    @EruptField(
        views = [View(title = "商品金额满多少可用")],
        edit = Edit(
            title = "商品金额满多少可用",
            notNull = true,
            search = Search(),
        ),
    )
    var priceMax: Double = 0.0

    @EruptField(
        views = [View(title = "发行量")],
        edit = Edit(
            title = "发行量",
            notNull = true,
            search = Search(vague = true),
        ),
    )
    var maxCount: Int = 0

    @EruptField(
        views = [
            View(
                title = "颜色",
                template = "'<div style=\"width:100%;height:20px;background:'+value+'\"></div>'",
            ),
        ],
        edit = Edit(
            title = "颜色",
            notNull = true,
            inputType = InputType(type = "color"),
        ),
    )
    var color: String = ""

    @EruptField(
        views = [View(title = "生效时间")],
        edit = Edit(
            title = "生效时间",
            notNull = true,
            dateType = DateType(type = DateType.Type.DATE_TIME),
        ),
    )
    var startTime: Date = Date()

    @EruptField(
        views = [View(title = "失效时间")],
        edit = Edit(
            title = "失效时间",
            notNull = true,
            dateType = DateType(type = DateType.Type.DATE_TIME),
        ),
    )
    var endTime: Date = Date()

    @ManyToOne
    @EruptField(
        views = [View(title = "指定类别商品可用", column = "name")],
        edit = Edit(
            title = "指定类别商品可用",
            desc = "不选择全场可用",
            type = EditType.REFERENCE_TREE,
            search = Search(),
            referenceTreeType = ReferenceTreeType(pid = "parent.id"),
        ),
    )
    var category: GoodsCategory? = null

}